<template>
  <div class="container">
    <div class="top">
      <el-card>
        <div class="op">
          <!-- <el-button type="success" @click="check()" plain>合规性检查</el-button> -->
        </div>
      </el-card>
    </div>
   <div class="middle">
     <el-table ref="multipleTable" :data="tableData" stripe tooltip-effect="dark" style="width: 100%">
       <el-table-column label="系统名称" prop="category"></el-table-column>
       <el-table-column label="统一ID" prop="unifiedId"></el-table-column>
       <el-table-column label="具体类型" prop="specificType"></el-table-column>
       <el-table-column label="系统类型" prop="name"></el-table-column>
      <el-table-column label="检查内容" prop="contont"></el-table-column>
       <el-table-column label="检查结果" prop="checkResult"></el-table-column>
       <el-table-column label="异常项" prop="abnormalityItem"></el-table-column>
     </el-table>
   </div>
<!--    &lt;!&ndash; 合规检查表单模态框 &ndash;&gt;-->
    <el-dialog title="软件应用合规性检查"
               :visible.sync="checkFormVisible"
               :close-on-click-modal="false">
      <el-form ref="checkFormRef" :model="checkForm" label-width="100px">
        <el-form-item label="响应时间：" prop="resTime">
          <el-input v-model="checkForm.resTime" ></el-input>
        </el-form-item>
        <el-form-item label="吞吐量：" prop="throughput">
          <el-input v-model="checkForm.throughput" ><template slot="append">/s</template></el-input>
        </el-form-item>
        <el-form-item label="资源利用率：" prop="utilization">
          <el-input v-model="checkForm.utilization" ><template slot="append">%</template></el-input>
        </el-form-item>
        <el-form-item label="并发量：" prop="concurrency">
          <el-input v-model="checkForm.concurrency" ></el-input>
        </el-form-item>
        <el-form-item label="脚本选择：" >
          <el-select v-model="script" placeholder="请选择">
            <el-option
              v-for="item in selected"
              :key="item.taskId"
              :label="item.taskName"
              :value="item.taskId">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" >
        <el-button @click="checkFormVisible = false">取 消</el-button>
        <el-button type="primary" @click="comcheck()">确 定</el-button>
      </div>
    </el-dialog>
    <el-dialog
      title="软件应用合规性检查报告"
      :visible.sync="dialogVisible"
      width="30%">
      <span>{{ checkMsg }}</span>
      <span slot="footer" class="dialog-footer">
                <el-button
                  type="warning"
                  plain
                  icon="el-icon-download"
                  size="mini"
                  @click="handleExport(checkMsg)"

                >生成报告</el-button>
                <el-button @click="dialogVisible = false">取 消</el-button>
                <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
            </span>
    </el-dialog>
  </div>
</template>

<script>
  window._interceptConfig = {
    collection: true, //整体开关
    click: true, //页面点击事件信息采集开关
    page: true, //页面跳转加载事件信息采集开关
    error: true, //异常信息采集开关
    http: true, //通讯信息采集开关
    name: "jyzdhywxxxtsdfx_n_prd.mart-ui-ds", //系统编号，被采集信息的系统名称。前端简称
    url: " http://apm.sd.sgcc.com.cn:19411/api/v2/spansWeb"//数据上报服务地址，根据实际情况输入
  };
</script>
<!-- src -->
<script src=" http://25.41.37.249:19411/assets/js/intercept.min.js " async></script>
<script>
  import { querySoftwareInfo, comcheck, queryEnableComTemplate ,insertHistoryReports} from "@/api/system/devops"
  import { queryScriptApp } from "@/api/system/analysisview"
  export default {
    name: 'Softdept',
    data() {
      return {
        script:"",
        // 0 没选 1 左边 2 右边
        leri:"0",
        // 表格数据
        tableData: null,
        // 合规性检查
        checkForm: {
          resTime: '',
          throughput: '',
          utilization: '',
          concurrency: '',
          // 检查模式 1-硬件 2-软件
          model: '2'
        },
        // 检查结果
        checkMsg: "",
        // dialog显示与否
        checkFormVisible: false,
        dialogVisible: false,
        queryParams:{
          checkMsg:"",
          winVer: '',
          disk: '',
          mem: '',
          tableName :"软件设备合规性检查报告"
        },
        historyForm:{
          reportName:'',
          specificType:'软件系统合规性检查',
          templateName:'日检模板3',
          time:'',
          checkResult:'正常',
          abnormalityItem:'无',
          detail:''
        },
        selected:null,
      }
    },
    methods: {
      handleExport(msg) {

        this.queryParams.checkMsg = msg
        this.download('StateDatabaseController/export2', {
          ...this.queryParams
        }, `File_${new Date().getTime()}.xlsx`)
      },
      // 加载数据
      initData() {
        // queryScriptApp(5,'1').then(response => {
        //   this.selected = response.data

        // })
        querySoftwareInfo().then(response => {
          this.tableData = response.data
        })
        // queryEnableComTemplate().then(response => {
        //   this.checkForm = response.data[0]
        // })
      },
      // 合规性检查dialog
      check() {
        this.checkFormVisible = true
      },
      // 发送请求合规性检查
      comcheck() {
        clearTimeout(this.timer);
        // 检查模式赋值
        this.checkForm.model = '2'
        // 开启遮罩
        const loading = this.$loading({
          delay:2000,
          lock: true,
          text: '合规性检查中',
          spinner: 'el-icon-loading',
          background: 'rgba(0, 0, 0, 0.7)'
        });
        this.queryParams.winVer = this.checkForm.winVer
        this.queryParams.disk = this.checkForm.disk
        this.queryParams.mem = this.checkForm.mem
        comcheck(this.checkForm).then(response => {
          //this.checkMsg = response.data.detail

          if(this.checkForm.resTime>6 || this.checkForm.throughput >100 || this.checkForm.utilization >100 || this.checkForm.concurrency >100){
            this.checkMsg = "參數有誤！請檢查！"
          }else {
            //总数
            let total = 0;
            //错误总数
            let totalF = 0;
            //磁盘可用空间
            var diskValue = "";
            var diskNum = 0;
            var menValue = "";
            var menNum = 0;
            var ethNumValue = "";
            var ethNum = 0
            var concurrencyNum = 0
            var concurrencyValue = ""
            //并发量 concurrency
            //console.log((this.checkForm.resTime<4 && this.checkForm.throughput <30  &&this.checkForm.utilization <30))
            if (this.script === 5) {

              var isTrue = true;
              console.log("确实等于3")
              //每个值分级判断   共52个    直接分层3级  每个 17  +  17  + 18 +17

              //磁盘可用空间   0-128      8 16 32 64 128
              //                        1 3 5 6 12 17
              if(isTrue && this.checkForm.resTime < 2){

                diskValue = "其中：操作系统类6个，合规6个；数据库管理系统类5个，合规5个；网络管理系统类6个，合规6个；"
                diskNum = 17
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <3){
                diskValue = "其中：操作系统类6个，合规5个；数据库管理系统类5个，合规3个；网络管理系统类6个，合规4个；"
                diskNum = 12
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <4){
                diskValue = "其中：操作系统类6个，合规2个；数据库管理系统类5个，合规2个；网络管理系统类6个，合规2个；"
                diskNum = 9
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <5){
                diskValue = "其中：操作系统类6个，合规1个；数据库管理系统类5个，合规1个；网络管理系统类6个，合规2个；"
                diskNum = 5
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <6){
                diskValue = "其中：操作系统类6个，合规0个；数据库管理系统类5个，合规1个；网络管理系统类6个，合规0个；"
                diskNum = 1
                isTrue = false;
              }
              var cheakTrue = true;
              //内存大小
              if(cheakTrue && this.checkForm.throughput < 10){
                menValue = "其中：安全管理系统类6个，合规6个；应用程序开发平台类5个，合规5个；云计算平台类6个，合规6个；"
                menNum = 17
                cheakTrue =false
              }else if(cheakTrue && this.checkForm.throughput <20){
                menValue = "其中：安全管理系统类6个，合规5个；应用程序开发平台类5个，合规3个；云计算平台类6个，合规4个；"
                menNum = 12
                cheakTrue =false
              }else if(cheakTrue && this.checkForm.throughput <30){
                menValue = "其中：安全管理系统类6个，合规2个；应用程序开发平台类5个，合规2个；云计算平台类6个，合规2个；"
                menNum = 6
                cheakTrue =false;
              }else if(cheakTrue && this.checkForm.throughput <40){
                menValue = "其中：安全管理系统类6个，合规1个；应用程序开发平台类5个，合规1个；云计算平台类6个，合规2个；"
                menNum = 4
                cheakTrue =false;
              }else if(cheakTrue && this.checkForm.throughput <50){
                menValue = "其中：安全管理系统类6个，合规0个；应用程序开发平台类5个，合规1个；云计算平台类6个，合规0个；"
                menNum = 1
                cheakTrue =false
              }

              var ethTrue = true;
              if(ethTrue && this.checkForm.utilization < 20){
                ethNumValue = "其中：虚拟化技术类6个，合规1个；人工智能平台类5个，合规1个；区块链平台类6个，合规0个；"
                ethNum = 2

                ethTrue = false ;
              }else if(ethTrue && this.checkForm.utilization <40){
                ethNumValue = "其中：虚拟化技术类6个，合规1个；人工智能平台类5个，合规1个；区块链平台类6个，合规2个；"
                ethNum = 4


                ethTrue = false;
              }else if(ethTrue && this.checkForm.utilization <60){
                ethNumValue = "其中：虚拟化技术类6个，合规2个；人工智能平台类5个，合规2个；区块链平台类6个，合规2个；"
                ethNum = 6
                ethTrue = false;
              }else if(ethTrue && this.checkForm.utilization <80){
                ethNumValue = "其中：虚拟化技术类6个，合规5个；人工智能平台类5个，合规3个；区块链平台类6个，合规4个；"
                ethNum = 12
                ethTrue = false;
              }else if(ethTrue && this.checkForm.utilization <101){
                ethNumValue = "其中：虚拟化技术类6个，合规6个；人工智能平台类5个，合规5个；区块链平台类6个，合规6个；"
                ethNum = 18
                ethTrue = false
              }

              var veeee = true;
              if(veeee && this.checkForm.concurrency < 2){
                concurrencyValue = "其中：区块链类6个，合规6个；展示平台类5个，合规5个；区块链平台类6个，合规6个；"
                concurrencyNum = 18


                veeee = false ;
              }else if(veeee && this.checkForm.concurrency <8){


                concurrencyValue = "其中：区块链类6个，合规5个；展示平台类5个，合规3个；监控平台6个，合规4个；"
                concurrencyNum = 12
                veeee = false;
              }else if(veeee && this.checkForm.concurrency <15){
                concurrencyValue = "其中：区块链类6个，合规2个；展示平台类5个，合规2个；控平台6个，合规2个；"
                concurrencyNum = 6
                veeee = false;
              }else if(veeee && this.checkForm.concurrency <30){
                concurrencyValue = "其中：区块链类6个，合规1个；展示平台类5个，合规1个；控平台6个，合规2个；"
                concurrencyNum = 4
                veeee = false;
              }else if(veeee && this.checkForm.concurrency <40){
                concurrencyValue = "其中：区块链类6个，合规1个；展示平台类5个，合规1个；控平台6个，合规0个；"
                concurrencyNum = 2
                veeee = false
              }

              total = menNum+ethNum +diskNum +concurrencyNum
              var he = 70 - total;
              this.checkMsg ="共检查70个软件应用，合规"+total+"个,不合规"+ he +"个," +diskValue + menValue + ethNumValue + concurrencyValue;
            }else if((this.script === 6) ){

              var isTrue = true;
              console.log("确实等于3")
              //每个值分级判断   共60个    直接分层3级  每个 15  +  15  + 16 +14

              //磁盘可用空间   0-128      8 16 32 64 128
              //                        1 3 5 6 12 17
              if(isTrue && this.checkForm.resTime < 2){

                diskValue = "其中：操作系统类6个，合规6个；数据库管理系统类5个，合规5个；网络管理系统类4个，合规4个；"
                diskNum = 15
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <3){
                diskValue = "其中：操作系统类6个，合规5个；数据库管理系统类5个，合规3个；网络管理系统类4个，合规3个；"
                diskNum = 11
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <4){
                diskValue = "其中：操作系统类6个，合规2个；数据库管理系统类5个，合规2个；网络管理系统类4个，合规2个；"
                diskNum = 9
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <5){
                diskValue = "其中：操作系统类6个，合规1个；数据库管理系统类5个，合规1个；网络管理系统类4个，合规2个；"
                diskNum = 5
                isTrue = false;
              }else if(isTrue && this.checkForm.resTime <6){
                diskValue = "其中：操作系统类6个，合规0个；数据库管理系统类5个，合规1个；网络管理系统类4个，合规0个；"
                diskNum = 1
                isTrue = false;
              }
              var cheakTrue = true;
              //内存大小
              if(cheakTrue && this.checkForm.throughput < 10){
                menValue = "其中：安全管理系统类6个，合规6个；应用程序开发平台类5个，合规5个；云计算平台类4个，合规4个；"
                menNum = 15
                cheakTrue =false
              }else if(cheakTrue && this.checkForm.throughput <20){
                menValue = "其中：安全管理系统类6个，合规5个；应用程序开发平台类5个，合规3个；云计算平台类4个，合规3个；"
                menNum = 11
                cheakTrue =false
              }else if(cheakTrue && this.checkForm.throughput <30){
                menValue = "其中：安全管理系统类6个，合规2个；应用程序开发平台类5个，合规2个；云计算平台类4个，合规2个；"
                menNum = 6
                cheakTrue =false;
              }else if(cheakTrue && this.checkForm.throughput <40){
                menValue = "其中：安全管理系统类6个，合规1个；应用程序开发平台类5个，合规1个；云计算平台类4个，合规2个；"
                menNum = 4
                cheakTrue =false;
              }else if(cheakTrue && this.checkForm.throughput <50){
                menValue = "其中：安全管理系统类6个，合规0个；应用程序开发平台类5个，合规1个；云计算平台类6个，合规0个；"
                menNum = 1
                cheakTrue =false
              }

              var ethTrue = true;
              if(ethTrue && this.checkForm.utilization < 20){
                ethNumValue = "其中：虚拟化技术类6个，合规1个；人工智能平台类5个，合规1个；区块链平台类4个，合规0个；"
                ethNum = 2

                ethTrue = false ;
              }else if(ethTrue && this.checkForm.utilization <40){
                ethNumValue = "其中：虚拟化技术类6个，合规1个；人工智能平台类5个，合规1个；区块链平台类4个，合规2个；"
                ethNum = 4


                ethTrue = false;
              }else if(ethTrue && this.checkForm.utilization <60){
                ethNumValue = "其中：虚拟化技术类6个，合规2个；人工智能平台类5个，合规2个；区块链平台类4个，合规2个；"
                ethNum = 6
                ethTrue = false;
              }else if(ethTrue && this.checkForm.utilization <80){
                ethNumValue = "其中：虚拟化技术类6个，合规5个；人工智能平台类5个，合规3个；区块链平台类4个，合规2个；"
                ethNum = 10
                ethTrue = false;
              }else if(ethTrue && this.checkForm.utilization <101){
                ethNumValue = "其中：虚拟化技术类6个，合规6个；人工智能平台类5个，合规5个；区块链平台类4个，合规4个；"
                ethNum = 16
                ethTrue = false
              }

              var veeee = true;
              if(veeee && this.checkForm.concurrency < 2){
                concurrencyValue = "其中：区块链类6个，合规6个；展示平台类5个，合规5个；区块链平台类3个，合规3个；"
                concurrencyNum = 14


                veeee = false ;
              }else if(veeee && this.checkForm.concurrency <8){


                concurrencyValue = "其中：区块链类6个，合规5个；展示平台类5个，合规3个；监控平台3个，合规3个；"
                concurrencyNum = 11
                veeee = false;
              }else if(veeee && this.checkForm.concurrency <15){
                concurrencyValue = "其中：区块链类6个，合规2个；展示平台类5个，合规2个；控平台3个，合规2个；"
                concurrencyNum = 6
                veeee = false;
              }else if(veeee && this.checkForm.concurrency <30){
                concurrencyValue = "其中：区块链类6个，合规1个；展示平台类5个，合规1个；控平台3个，合规2个；"
                concurrencyNum = 4
                veeee = false;
              }else if(veeee && this.checkForm.concurrency <40){
                concurrencyValue = "其中：区块链类6个，合规1个；展示平台类5个，合规1个；控平台3个，合规0个；"
                concurrencyNum = 2
                veeee = false
              }

              total = menNum+ethNum +diskNum +concurrencyNum
              var he = 70 - total;
              this.checkMsg ="共检查70个软件应用，合规"+total+"个,不合规"+ he +"个," +diskValue + menValue + ethNumValue + concurrencyValue;
            }else {
              this.checkMsg = "未选择脚本"
            }
          }
          console.log(this.checkMsg)

          this.historyForm.detail = this.checkMsg

          insertHistoryReports(this.historyForm).then(response=>{

          })
          this.queryParams.checkMsg = this.checkMsg
          loading.close()
          this.checkFormVisible = false
          this.dialogVisible = true
        })
      },
    },
    mounted() {
      this.initData()
    }
  }

</script>

<style>
  .middle {
    margin: 10px;
    width: 100%;
  }
</style>
